package com.zyk.scaffold.tmp;

import cn.hutool.core.date.StopWatch;
import com.zyk.scaffold.common.utils.RandomUtils;
import com.zyk.scaffold.common.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class Tmp {
    static int[] target = new int[10];
    static String splitStr = "/";
    static List<String> list = new ArrayList<String>();
    public static void main(String[] args){
        for(int i = 0;i < 100; i++){
            push("aaaaa" + i + splitStr +"BBBBB" + i + splitStr + "CCCCC" + i + splitStr + "DDDDD" + i);
        }
//        push("Cq75C/30131/NZ2L2/b0XWs");
        System.out.println("数据生产完成");
        StopWatch checkStr = StopWatch.create("1111");
        checkStr.start("checkStr");
        System.out.println(checkStr("Cq75C/30131/NZ2L2/b0XWs"));
        checkStr.stop();
        System.out.println("数据碰撞查找完成");
        checkStr.start("findStr");
        System.out.println(findStr("Cq75C/30131/NZ2L2/b0XWs"));
        checkStr.stop();
        System.out.println("数据查找完成");
        System.out.println(checkStr);
        System.out.println(checkStr.getTotal(TimeUnit.SECONDS));
    }

    private static boolean findStr(String s) {
        for (String s1 : list) {
            if(s1.equals(s)){
                return true;
            }
        }
        return false;
    }

    private static void push(String s) {
        list.add(s);
        String[] split = s.trim().split(splitStr);
        for (int i = 0; i < split.length; i++) {
            target[i] = target[i] | (1 << (split[i].hashCode() % 32));
        }
    }
    private static boolean checkStr(String s) {
        String[] split = s.trim().split(splitStr);
        for (int i = 0; i < split.length; i++) {
            if(i + 1 == target.length){
                return true;
            }
            if( 1 == (1 & (target[i] >> (split[i].hashCode() % 32)))){
                continue;
            }
            return false;
        }
        return true;
    }
}
